package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/11/17 16:28
 * @description 258. 各位相加
 */
public class Test258 {

    public static void main(String[] args) {
        System.out.println(addDigits(0));
    }
    public static int addDigits(int num) {

        while (num >= 10) {
            int count = 0;
            while (num != 0) {
                count += num % 10;
                num /= 10;
            }
            num = count;
        }
        return num;
    }

    public int addDigits2(int num) {
        return (num - 1) % 9 + 1;
    }

    public int addDigits3(int num) {
        int i = num % 9;
        if (i == 0) {
            return 9;
        }
        return i;
    }
}
